# -*- coding: utf-8 -*-

class router:
    def __init__(self) -> None:
        self.interfaces_ip = []     # 端口上 ip 号的数组，str 类型
        # self.networks_ip = []       # 端口上网络号的数组，str 类型，网络号/掩码
        # self.networks_name = []     # 端口上网络名的数组，str 类型，自定义名称
        self.name = ""              # 路由器名称，“Rn”，“Dn”
        self.type = 0               # 路由器类型：0-主机 1-RIP 2-OSPF 3-路由重分配

    def get_network_ip(self, index: int):
        ip = self.interfaces_ip[index]
        temp = ip.split('.')
        return temp[0] + '.' + temp[1] + '.' + temp[2] + '.0'
    
    def get_network_name(self, index: int):
        nip = self.get_network_ip(index=index)
        return nip.replace('.', '0')

class config:
    def __init__(self) -> None:
        self.routers = []   # 用 routers[i-1] 来获取 Ri
        self.devices = []
        self.set_routers()
        self.set_devices()

    def set_routers(self):
        r = router()
        r.name = "R1"
        r.interfaces_ip.append("200.2.4.1")
        r.interfaces_ip.append("200.2.1.1")
        r.interfaces_ip.append("200.2.2.1")
        r.type = 1
        self.routers.append(r)

        r = router()
        r.name = "R2"
        r.interfaces_ip.append("200.2.3.2")
        r.interfaces_ip.append("200.2.1.2")
        r.interfaces_ip.append("200.1.9.1")
        r.type = 1
        self.routers.append(r)

        r = router()
        r.name = "R3"
        r.interfaces_ip.append("200.2.3.1")
        r.interfaces_ip.append("200.2.2.2")
        r.interfaces_ip.append("200.2.5.1")
        r.type = 1
        self.routers.append(r)

        r = router()
        r.name = "R4"
        r.interfaces_ip.append("200.3.3.1")
        r.interfaces_ip.append("200.3.1.1")
        r.interfaces_ip.append("200.2.5.2")
        r.type = 3
        self.routers.append(r)

        r = router()
        r.name = "R5"
        r.interfaces_ip.append("200.3.2.1")
        r.interfaces_ip.append("200.3.1.2")
        r.type = 2
        self.routers.append(r)

        r = router()
        r.name = "R6"
        r.interfaces_ip.append("200.3.3.2")
        r.type = 2
        self.routers.append(r)

        r = router()
        r.name = "R7"
        r.interfaces_ip.append("200.1.9.2")
        r.interfaces_ip.append("200.1.7.2")
        r.interfaces_ip.append("200.1.5.1")
        r.type = 3
        self.routers.append(r) 

        r = router()
        r.name = "R8"
        r.interfaces_ip.append("200.1.6.1")
        r.interfaces_ip.append("200.1.7.1")
        r.interfaces_ip.append("200.1.8.1")
        r.type = 2
        self.routers.append(r) 

        r = router()
        r.name = "R9"
        r.interfaces_ip.append("200.1.6.2")
        r.interfaces_ip.append("200.1.3.2")
        r.interfaces_ip.append("200.1.2.1")
        r.type = 2
        self.routers.append(r) 

        r = router()
        r.name = "R10"
        r.interfaces_ip.append("200.1.3.1")
        r.interfaces_ip.append("200.1.5.2")
        r.interfaces_ip.append("200.1.4.1")
        r.type = 2
        self.routers.append(r) 

        r = router()
        r.name = "R11"
        r.interfaces_ip.append("200.1.2.2")
        r.interfaces_ip.append("200.1.1.1")
        r.type = 2
        self.routers.append(r) 

    def set_devices(self):
        d = router()
        d.name = "D1"
        d.interfaces_ip.append("200.2.4.2")
        self.devices.append(d)

        d = router()
        d.name = "D2"
        d.interfaces_ip.append("200.1.4.2")
        self.devices.append(d)

        d = router()
        d.name = "D3"
        d.interfaces_ip.append("200.3.2.2")
        self.devices.append(d)

        d = router()
        d.name = "D4"
        d.interfaces_ip.append("200.1.8.2")
        self.devices.append(d)

        d = router()
        d.name = "D5"
        d.interfaces_ip.append("200.1.1.2")
        self.devices.append(d)
